#include "sdf.h"
#include <stdio.h>
#include <stdlib.h>

int main() {
    void *pdh;
    pdh = (void *)malloc(20);
    int ret;

    ret = SDF_OpenDevice(&pdh);
    if (ret != SDR_OK) {
        printf("error!\n");
    } else {
        printf("device opened!\n");
    }

    // 测试生成不同长度的随机数
    printf("Testing 1 byte:\n");
    char random1[1];
    ret = SDF_GenerateRandom(pdh, 1, (unsigned char *)random1);
    if (ret == SDR_OK) {
        printf("%d\n", random1[0]);
    }

    printf("Testing 5 bytes:\n");
    char random5[5];
    ret = SDF_GenerateRandom(pdh, 5, (unsigned char *)random5);
    if (ret == SDR_OK) {
        for (int i = 0; i < 5; i++) {
            printf("%d ", random5[i]);
        }
        printf("\n");
    }

    printf("Testing 20 bytes:\n");
    char random20[20];
    ret = SDF_GenerateRandom(pdh, 20, (unsigned char *)random20);
    if (ret == SDR_OK) {
        for (int i = 0; i < 20; i++) {
            printf("%d ", random20[i]);
        }
        printf("\n");
    }

    ret = SDF_CloseDevice(pdh);
    if (ret != SDR_OK) {
        printf("error!\n");
    } else {
        free(pdh);
        printf("device closed!\n");
    }

    return 0;
}
